import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [

  // 登录路由
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  // 404错误路由
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  // 主菜单路由
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [{
      path: 'home',
      name: '首页',
      component: () => import('@/views/home/index')
    }]
  },

  // 个人主页
  {
    path: '/personal',
    component: Layout,
    redirect: '/personal/info',
    meta: { title: '个人中心', icon: 'peoples' },
    children: [{
      path: 'info',
      name: 'info',
      component: () => import('@/views/home/editor/index')
    }]
  },

  // 用户管理路由：琴台用户管理、后台用户管理
  {
    path: '/user',
    component: Layout,
    redirect: '/user/user',
    name: 'Example',
    meta: { title: '用户管理', icon: 'peoples' },
    children: [
      {
        path: 'user',
        name: 'User',
        component: () => import('@/views/user/user'),
        meta: { title: '前台用户管理', icon: 'qq' }
      },
      {
        path: 'admin',
        name: 'Admin',
        component: () => import('@/views/user/admin'),
        meta: { title: '后台用户管理', icon: 'user' }
      }
    ]
  },

  // 帖子管理路由：未审核，已审核
  {
    path: '/post',
    component: Layout,
    redirect: '/post/auditPost',
    name: 'Post',
    meta: { title: '帖子管理', icon: 'education' },
    children: [
      {
        path: 'auditPost',
        name: 'AuditPost',
        component: () => import('@/views/post/auditPost'),
        meta: { title: '待审核', icon: 'form' }
      },
      {
        path: 'audit/:id(\\d+)',
        component: () => import('@/views/post/audit'),
        name: 'Audit',
        meta: { title: '帖子审核', noCache: true, activeMenu: '/post/unauditedPost' },
        hidden: true
      },
      {
        path: 'searchPost',
        name: 'SearchPost',
        component: () => import('@/views/post/viewPost'),
        meta: { title: '查询帖子', icon: 'search' }
      },
      {
        path: 'view/:id(\\d+)',
        component: () => import('@/views/post/view'),
        name: 'View',
        meta: { title: '帖子审核', noCache: true, activeMenu: '/post/viewPost' },
        hidden: true
      }
    ]
  },

  // 查询分析：按标签、阅读量、评论数、点赞数进行统计
  {
    path: '/analyse',
    component: Layout,
    redirect: '/analyse/chart1',
    name: 'Analyse',
    meta: { title: '查询统计', icon: 'chart' },
    children: [
      {
        path: 'chart1',
        name: 'Chart1',
        component: () => import('@/views/statistics/lineChart'),
        meta: { title: '最近两周发帖量', icon: 'international' }
      },
      {
        path: 'chart2',
        name: 'Chart2',
        component: () => import('@/views/statistics/barChart'),
        meta: { title: '最近六个月发帖量', icon: 'international' }
      },
      {
        path: 'chart3',
        name: 'Chart3',
        component: () => import('@/views/statistics/pieChart'),
        meta: { title: '热门标签统计', icon: 'international' }
      }
    ]
  },

  // 日志管理：后台登录日志
  {
    path: '/logs',
    component: Layout,
    redirect: '/logs/loginLog',
    name: 'Logs',
    alwaysShow: true,
    meta: { title: '日志记录', icon: 'education' },
    children: [
      {
        path: 'loginLog',
        name: 'LoginLog',
        component: () => import('@/views/logs/loginLog'),
        meta: { title: '登录日志', icon: 'form' }
      }
    ]
  },
  // 监控中心
  {
    path: '/monitor',
    component: Layout,
    redirect: '/monitor/gitlab',
    name: 'Monitor',
    meta: { title: '监控中心', icon: 'eye-open' },
    children: [
      // {
      //   path: 'gitlab',
      //   name: 'GitLab',
      //   component: () => import('@/views/monitor/GitLab'),
      //   meta: { title: 'GitLab', icon: 'international' }
      // },
      // {
      //   path: 'nexus',
      //   name: 'Nexus',
      //   component: () => import('@/views/monitor/Nexus'),
      //   meta: { title: 'Nexus-Maven私服', icon: 'international' }
      // },
      // {
      //   path: 'dockerRegistry',
      //   name: 'DockerRegistry',
      //   component: () => import('@/views/monitor/DockerRegistry'),
      //   meta: { title: 'Docker Registry', icon: 'international' }
      // },
      {
        path: 'eureka',
        name: 'Eureka',
        component: () => import('@/views/monitor/Eureka'),
        meta: { title: 'Eureka', icon: 'international' }
      },
      {
        path: 'zipKin',
        name: 'ZipKin',
        component: () => import('@/views/monitor/ZipKin'),
        meta: { title: 'ZipKin', icon: 'international' }
      },
      {
        path: 'springBootAdmin',
        name: 'SpringBootAdmin',
        component: () => import('@/views/monitor/SpringBootAdmin'),
        meta: { title: 'Spring Boot Admin', icon: 'international' }
      }
    ]
  },

  // 友情链接
  {
    path: 'link',
    component: Layout,
    redirect: '/link',
    name: 'Link',
    meta: { title: '友情链接', icon: 'eye-open' },
    children: [
      {
        path: 'http://119.3.162.93:8080/SCMS/',
        meta: { title: 'SCMS', icon: 'guide' }
      },
      {
        path: 'https://github.com/moxi624/mogu_blog_v2',
        meta: { title: 'Mogu 仓库', icon: 'guide' }
      },
      {
        path: 'http://www.moguit.cn/',
        meta: { title: 'Mogu前台 演示', icon: 'guide' }
      },
      {
        path: 'http://demoadmin.moguit.cn/',
        meta: { title: 'Mogu后台 演示', icon: 'guide' }
      },
      {
        path: 'https://panjiachen.github.io/vue-admin-template/',
        meta: { title: 'Vue-template 演示', icon: 'guide' }
      },
      {
        path: 'https://github.com/PanJiaChen/vue-admin-template',
        meta: { title: 'Vue-template 仓库', icon: 'guide' }
      },
      {
        path: 'https://panjiachen.github.io/vue-element-admin/',
        meta: { title: 'Vue-admin 演示', icon: 'guide' }
      },
      {
        path: 'https://github.com/PanJiaChen/vue-element-admin/',
        meta: { title: 'Vue-admin 仓库', icon: 'guide' }
      },
      {
        path: 'https://panjiachen.gitee.io/vue-element-admin-site/zh/guide/',
        meta: { title: 'Vue-admin Doc', icon: 'guide' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  // 默认路由方式，匹配任意不存在的路径，跳转到404页面
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
